// pages/search_main/search_main.js
const app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        association: [],
        is_empty: false,
        
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.renderAssociationList();
    },

    /**
     * 下拉刷新
     */
    onPullDownRefresh: function () {
        wx.showLoading({
            title: '正在刷新',
        })
        this.renderAssociationList(function () {
            setTimeout(function () {
                wx.stopPullDownRefresh();
                wx.hideLoading()
            }, 500)
        })
    },

    //重新渲染数据
    renderAssociationList: function (cb) {
        let setdata = {};
        setdata['course'] = [];
        this.setData(setdata)
        this.getAssociationList(cb);
    },

    //获取社团文化列表
    getAssociationList: function (cb) {
        let _this = this;
        app._get('/api/login/association/getAssociation', null, function (response) {
            let data = response.data.data;
            let setdata = {};
            if (data.length == 0) {
                setdata['is_empty'] = true;
            } else {
                setdata['is_empty'] = false;
                setdata['association'] = data;
            }
            _this.setData(setdata);
        })
        typeof cb == 'function' && cb();
    },

    /**
     * 去详情
     */
    toAssociationDetail: function(e){
        wx.navigateTo({
          url: '/pages/association_detail/association_detail?association_id='+e.currentTarget.dataset.association_id,
        })
    },

})